#include "thread.h"

int myls(int netfd,dirID_t*dirID){


    train_t train;
    bzero(&train,sizeof(train_t));
    char pwd[256];
    char realPwd[256];

    bzero(pwd,256);
    bzero(realPwd,256);
    get_user_dir(pwd,dirID);
    strcpy(realPwd,dirID->pwdID);
    printf("realPwd = %s\n",realPwd);
    strcat(realPwd,pwd);
    printf("2realPwd = %s\n",realPwd);
    struct dirent *pentry;

    DIR *pdir=opendir(realPwd);

    if(pdir==NULL){
        perror("opendir");
        return 1;
    }

    while((pentry=readdir(pdir))!=NULL){

        if(pentry->d_name[0]=='.'){
            continue;
        }

        strcat( train.buf,pentry->d_name );
        strcat( train.buf," " );
    }

    //printf("%s\n",ls);
    train.length=strlen(train.buf);
    printf("buf = %s\n",train.buf);
    send(netfd,&train.length,sizeof(int),MSG_NOSIGNAL);
    send(netfd,&train.buf,train.length,MSG_NOSIGNAL);

    closedir(pdir);
    return 0;
}

